//
//  SecondsToDateStringValueTransformer.m
//  EVE Mac Suite
//
//  Created by Vadim Lozko on 4/13/09.
//  Copyright 2009  __Vadim__. All rights reserved.
//

#import "SecondsToDateStringValueTransformer.h"


@implementation SecondsToDateStringValueTransformer

+ (Class)transformedValueClass
{
	return [NSString class];
}

+ (BOOL)allowsReverseTransformation
{
    return NO;
}

- (id)transformedValue:(id)value
{
	if(value == nil || [value doubleValue] == 0) return @"";
	double seconds = [(NSNumber*)value doubleValue];
	NSDate* finishDate = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval)seconds];
	NSString* selectedTimeZoneString = [[NSUserDefaults standardUserDefaults] stringForKey:@"selectedTimeZone"];
	NSTimeZone* timeZone;
	if([selectedTimeZoneString isEqualToString:@"Local Time"])
	{
		timeZone = [NSTimeZone localTimeZone];
	} else {
		timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
	}
	NSString* selectedDateFormat = [[NSUserDefaults standardUserDefaults] stringForKey:@"selectedDateFormat"];
	if([selectedDateFormat isEqualToString:@"dd/mm/yyyy"])
	{
		return [finishDate descriptionWithCalendarFormat:@"%d/%m/%Y %I:%M %p" timeZone:timeZone locale:nil];
	} else {
		return [finishDate descriptionWithCalendarFormat:@"%m/%d/%Y %I:%M %p" timeZone:timeZone locale:nil];
	}
}

@end
